<template>
  <div>
    <div>
      <mt-navbar v-model="ClassSelected" fixed>
        <div
          style="
            width: 10vw;
            display: flex;
            align-items: center;
            justify-content: center;
          "
          @click="$router.go(-1)"
        >
          <img
            style="width: 40%"
            src="@/assets/images/Hospital/back.png"
            alt=""
          />
        </div>
        <mt-tab-item id="1">医生</mt-tab-item>
        <mt-tab-item id="2">医院</mt-tab-item>
      </mt-navbar>
      <mt-tab-container v-model="ClassSelected" style="margin-top: 0.5vh">
        <mt-tab-container-item id="1">
          <div class="zbox" style="position: fixed; top: 5vh">
            <div class="container">
              <div :class="{ click: selected !== 0 }">
                <div class="menu">
                  <div class="select">
                    <div @click="selected = 1">
                      <span
                        v-html="keshivalue ? `${keshivalue}` : '选择科室'"
                      ></span>
                      <img
                        src="@/assets/images/Hospital/right.png"
                        :class="{ active: selected == 1 }"
                      />
                    </div>
                    <b>|</b>
                    <div @click="selected = 2">
                      <span
                        v-html="
                          vl == 1
                            ? '综合排序'
                            : vl == 2
                            ? '医保报销'
                            : vl == 3
                            ? '评分排序'
                            : ''
                        "
                      ></span>
                      <img
                        src="@/assets/images/Hospital/right.png"
                        :class="{ active: selected == 2 }"
                      />
                    </div>
                  </div>
                  <div class="show">
                    <div v-show="selected == 1">
                      <div @click="active" v-if="keshidata">
                        <span
                          v-for="{ key, ks } in keshidata.data"
                          :key="key"
                          @click="keshivalue = ks"
                          >{{ ks }}</span
                        >
                      </div>
                      <div class="btn" @click="selected = 0">
                        <div class="no">取消</div>
                        <div class="yes" @click="quedingkeshi">确定</div>
                      </div>
                    </div>
                    <div v-show="selected == 2">
                      <ul @click="active2">
                        <li class="active" @click="vl = 1">
                          <p>综合排序</p>
                          <img
                            src="@/assets/images/Hospital/select.png"
                            alt=""
                          />
                        </li>
                        <li @click="vl = 2">
                          <p>医保报销</p>
                          <img
                            src="@/assets/images/Hospital/select.png"
                            alt=""
                          />
                        </li>
                        <li @click="vl = 3">
                          <p>评分</p>
                          <img
                            src="@/assets/images/Hospital/select.png"
                            alt=""
                          />
                        </li>
                      </ul>
                      <div class="btn" @click="selected = 0">
                        <div class="no">取消</div>
                        <div class="yes" @click="paixu">确定</div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div style="margin-top: 13vh; padding: 0 3vw" v-if="docData">
            <doctor-card
              v-for="(zv, i) in docData.data"
              :key="i"
              :zv="zv"
              @click.native="$router.push(`/doctorDetail?${zv.did}`)"
            ></doctor-card>
          </div>
        </mt-tab-container-item>
        <mt-tab-container-item id="2">
          <div class="zbox" style="position: fixed; top: 5vh">
            <div class="container">
              <div :class="{ click: selected2 !== 0 }">
                <div class="menu">
                  <div class="select">
                    <div @click="selected2 = 1">
                      <span
                        v-html="keshivalue2 ? `${keshivalue2}` : '选择科室'"
                      ></span>
                      <img
                        src="@/assets/images/Hospital/right.png"
                        :class="{ active: selected2 == 1 }"
                      />
                    </div>
                    <b>|</b>
                    <div @click="selected2 = 2">
                      <span>综合排序</span>
                      <img
                        src="@/assets/images/Hospital/right.png"
                        :class="{ active: selected2 == 2 }"
                      />
                    </div>
                  </div>
                  <div class="show">
                    <div v-show="selected2 == 1">
                      <div @click="active" v-if="keshidata">
                        <span @click="qdks = ''">全部科室</span>
                        <span
                          v-for="{ key, ks } in keshidata.data"
                          :key="key"
                          @click="keshivalue2 = ks,qdks = ks"
                          >{{ ks }}</span
                        >
                      </div>
                      <div class="btn" @click="selected2 = 0">
                        <div class="no">取消</div>
                        <div class="yes"  @click="selectks">确定</div>
                      </div>
                    </div>
                    <div v-show="selected2 == 2">
                      <ul @click="active2">
                        <li class="active" @click="key = ''">
                          <p>综合排序</p>
                          <img
                            src="@/assets/images/Hospital/select.png"
                            alt=""
                          />
                        </li>
                        <li  @click="key = 1">
                          <p>医保报销</p>
                          <img
                            src="@/assets/images/Hospital/select.png"
                            alt=""
                          />
                        </li>
                        <li @click="key = 2">
                          <p>职称</p>
                          <img
                            src="@/assets/images/Hospital/select.png"
                            alt=""
                          />
                        </li>
                      </ul>
                      <div class="btn" @click="selected2 = 0">
                        <div class="no">取消</div>
                        <div class="yes" @click="paixu">确定</div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div style="margin-top: 13vh" v-if="hosData">
            <hos-card
              @click.native="$router.push(`/detail?${hos.bid}`)"
              v-for="(hos, i) in hosData.data"
              :key="i"
              :zhos="hos"
            ></hos-card>
          </div>
        </mt-tab-container-item>
      </mt-tab-container>
    </div>
  </div>
</template>

<script>
import HosCard from "@/components/HosCard.vue";
import DoctorCard from "@/components/DoctorCard.vue";

export default {
  components: {
    HosCard,
    DoctorCard,
  },
  data() {
    return {
      ClassSelected: "1",
      selected: 0,
      selected2: 0,
      keshidata: null,
      docData: null,
      keshivalue: decodeURI(this.$route.fullPath.split("?")[1]),
      vl: 1,
      hosData: null,
      keshivalue2: "",
      qdks: "全部科室",
    };
  },
  mounted() {
    this.axios.get("/users/index_tese").then((res) => {
      this.keshidata = res.data;
    });
    this.axios.get(`/keshi_xu/${this.keshivalue}`).then((res) => {
      this.docData = res.data;
    });
    this.axios(`/users/hospital`).then((res) => {
      this.hosData = res.data;
    });
  },
  methods: {
    selectks() {
      this.axios(`/users/keshi_xu/${this.qdks}`).then((res) => {
        this.hosData = res.data;
      });
    },
    active(e) {
      if (e.target.nodeName !== "SPAN") return;
      let spans = document.querySelectorAll(".show span");
      spans.forEach((span) => {
        span.classList.remove("active");
      });
      e.target.classList.add("active");
    },
    active2(e) {
      let lis = document.querySelectorAll(".show li");
      lis.forEach((li) => {
        li.classList.remove("active");
      });
      e.target.classList.add("active");
    },
    quedingkeshi() {
      this.axios.get(`/keshi_xu/${this.keshivalue}`).then((res) => {
        this.docData = res.data;
      });
    },
    paixu() {
      this.axios.get(`/doctor_xu?vl=${this.vl}`).then((res) => {
        this.docData = res.data;
      });
    },
    paixu() {
      this.axios(`/users/keshi_xu?vl=${this.key}`).then((res) => {
        this.hosData = res.data;
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.zbox {
  padding: 0;
  top: 0;
  right: 0;
  width: 100%;
  background-color: #fff;
  .container {
    > div {
      &.click::after {
        content: "";
        position: absolute;
        height: 100vh;
        width: 100vw;
        background-color: #92929220;
      }
    }
  }
}
.menu {
  position: relative;
  top: 1vh;
  > .select {
    padding: 1vh 0;
    display: flex;
    align-items: center;
    > div {
      display: flex;
      justify-content: center;
      align-content: center;
      width: 50%;
      padding: 1vh;
      height: 3vh;
      > img {
        display: block;
        width: 8%;
        margin: 0 1vw;
        &.active {
          transform: rotate(90deg);
        }
      }
      > span {
        line-height: 3vh;
      }
    }
    > b {
      color: #d8d8d8;
    }
  }
  > .show {
        z-index: 1;

    > div {
      &:nth-child(1) {
        display: flex;
        flex-direction: column;
        & > div:first-child {
          max-height: 26vh;
          overflow: auto;
          padding: 3vw;
          > span {
            display: inline-block;
            width: fit-content;
            margin: 1.5%;
            padding: 1vh 3vh;
            text-align: center;
            background-color: #f0f0f0;
            border-radius: 0.75em;
            color: #333;
            &.active {
              background-color: #1397d7;
              color: #fff;
            }
          }
        }
      }
      > ul > li {
        border-bottom: 1px solid #d8d8d8;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 2vh 3vw;
        height: 2vh;
        > p {
          color: #333;
          pointer-events: none;
        }
        > img {
          width: 5%;
          display: none;
          pointer-events: none;
        }
        &.active {
          > p {
            color: #1397d7;
          }
          > img {
            display: block;
          }
        }
      }

      > .btn {
        background-color: #fff;
        display: flex;
        z-index: 1;
        > div {
          width: 50%;
          text-align: center;
          padding: 2vh;
          &:nth-child(2) {
            background-color: #1397d7;
            color: #fff;
          }
        }
      }
    }
  }
}
ul {
  margin: 0;
  padding: 0;
}

.hidden {
  display: none;
}
</style>

